package com.ezbuy.common.functions;

import com.ezbuy.common.functions.Consumer;

/**
 * 转移消费者,dest处理之后,src不再处理
 * ezbuy 2018/12/1 下午2:01
 */
public class TransferConsumer<T> implements Consumer<T> {

    //处理成功回调的consumer
    private Consumer<T> src;
    private Consumer<T> dest;

    public TransferConsumer(Consumer<T> src, Consumer<T> dest) {
        this.src = src;
        this.dest = dest;
    }

    @Override
    public void consume(T response) {
        if (dest != null) {
            dest.consume(response);
            return;
        }
        src.consume(response);
    }
}
